package cn.wb.base.controller;

import cn.wb.base.dto.PhoneRegisterDto;
import cn.wb.base.dto.SmsCodeDto;
import cn.wb.base.service.VerifyCodeService;
import cn.wb.base.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.io.IOException;

@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {

    @Autowired
    private VerifyCodeService verifyCodeService;

    /**
     * 获取图形验证码
     * @param imageCodeKey
     * @return
     */
    @GetMapping("/image/{imageCodeKey}")
    public AjaxResult imageCode(@PathVariable("imageCodeKey") String imageCodeKey) throws IOException {
      String imageCode=  verifyCodeService.imageCode(imageCodeKey);
        return AjaxResult.me().success(imageCode);
    }
    /**
     * 发送手机验证码
     * @param
     * @return
     */
    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody @Valid SmsCodeDto dto) {
       verifyCodeService.smsCode(dto);
        return AjaxResult.me().success();
    }

    /**
     * 手机号注册
     * @param
     * @return
     */
    @PostMapping("/phoneRegister")
    public AjaxResult phoneRegister(@RequestBody @Valid PhoneRegisterDto dto) {
        verifyCodeService.phoneRegister(dto);
        return AjaxResult.me().success();
    }


}
